import DGOpenLink from "../../../components/DGOpenLink.tsx";
import DGListView from "../../../components/DGListView.tsx";
import DGListViewItem from "../../../components/DGListViewItem.tsx";
import DGConnect from "../../../sources/DGConnect.ts";
import DGFooterView from "../../../components/DGFooterView/DGFooterView.tsx";
import DGFadeView from "../../../components/DGFadeView.tsx";
import AppProvider from "../../../sources/AppProvider.ts";
import {useEffect, useState} from "react";
import {useNavigate} from "react-router-dom";
import {Util} from "../../../sources/Util.ts";

const DGSecurityIndex = () => {
    // 全局上下文
    const App = AppProvider.useAppContext();
    // 时间提示语
    const [greeting, setGreeting] = useState("");
    // 跳转链接提示面板
    const [link, setLink] = useState({state: false, name: "", link: ""});
    // 路由跳转
    const router = useNavigate();


    // 关闭面板
    const handleClose = (id: number) => {
        setLink({state: false, name: link.name, link: link.link});
        if (id === 1) router(-1);
    }


    // 设置跳转链接面板
    // const handleSetLink = (state: boolean, name: string, link: string) => {
    //     // 设置链接面板信息
    //     setLink({state: state, name: name, link: link});
    //     // 推入历史堆栈
    //     router("?security");
    // }

    // 加载返回和后退识别
    useEffect(() => {
        const handlePopState = () => handleClose(0);
        window.addEventListener('popstate', handlePopState);
        return () => window.removeEventListener('popstate', handlePopState);
    }, []);

    useEffect(() => {
        const hour = new Date().getHours();
        if (hour >= 5 && hour < 9) setGreeting('早上好！一年之计在于春，一日之计在于晨，祝你有个充实的早晨！');
        else if (hour >= 9 && hour < 12) setGreeting('上午好！保持专注，今天一定会很有收获！');
        else if (hour >= 12 && hour < 14) setGreeting('中午好！别忘了好好休息一下，补充能量为下午做好准备！');
        else if (hour >= 14 && hour < 17) setGreeting('下午好！坚持不懈，下午的时光也要高效！');
        else if (hour >= 17 && hour < 19) setGreeting('傍晚好！忙碌了一天，记得放松一下，享受宁静的时光！');
        else if (hour >= 19 && hour < 23) setGreeting('晚上好！一天接近尾声，放松心情，享受愉快的夜晚！');
        else setGreeting('深夜了，工作和游戏固然重要，但健康更重要，记得注意休息！');
    }, []);

    useEffect(() => {
        App?.setTitle("安全中心");
    }, [App]);

    return (<DGFadeView time={1000}>
        {/* 打开链接弹窗 */}
        <DGOpenLink state={link.state} close={() => handleClose(1)} name={link.name} link={link.link}/>

        {/* 账户信息 */}
        <DGListView
            title="当前信息" subTitle={`尊敬的 ${App?.info ? App.info['name'] : "访客"}，${greeting}`}
            NoBackground Margin="10px" gap={10}>
            {/* 账号 */}
            <DGListViewItem
                alignItems="flex-start" avatar={DGConnect.img("forget_account.png")}
                title="我的账号" subText={`${App?.info ? App.info['account'] : "您未进行登录！"}`}/>
            {/* 邮箱 */}
            <DGListViewItem
                alignItems="flex-start" avatar={DGConnect.img("email.png")}
                title="我的邮箱" subText={`${App?.info ? App.info['email'] : "您未进行登录！"}`}/>
        </DGListView>


        {/* 账户类型表单列表 */}
        <DGListView title="安全中心" subTitle="部分自助表单需进行登录才能使用" NoBackground Margin="10px" gap={10}>
            {/* 操作记录 */}
            <DGListViewItem
                alignItems="flex-start" avatar={DGConnect.img("more_table.png")}
                title="操作记录" subText="查看您当前账户的操作记录。"
                onClick={() => router(Util.Storage.getSession("HOME") + "security/options")}/>
            {/* 安全信息 */}
            {/*<DGListViewItem*/}
            {/*    alignItems="flex-start" avatar={DGConnect.img("change_email.png")}*/}
            {/*    title="安全信息" subText="了解安全信息以更好保护自己账户。"*/}
            {/*    onClick={() => router(Util.Storage.getSession("HOME") + "security/info")}/>*/}
            {/* 自助表单 */}
            <DGListViewItem
                alignItems="flex-start" icon="自"
                title="自助表单" subText="查看所有的自助服务表单。"
                onClick={() => router(Util.Storage.getSession("HOME") + "security/selfTable")}/>
            {/* 在线表单 */}
            <DGListViewItem
                alignItems="flex-start" icon="线"
                title="在线表单" subText="查看所有的在线申请表单。"
                onClick={() => router(Util.Storage.getSession("HOME") + "security/onlineTable")}/>
            {/* 招贤纳士 */}
            {/*<DGListViewItem*/}
            {/*    avatar={DGConnect.img("recruit.png")}*/}
            {/*    title="招贤纳士" subText="点击填写加入申请表单"*/}
            {/*    onClick={() => handleSetLink(true, "招贤纳士申请表单", "https://docs.qq.com/form/page/DSkhwdWxDU3NJZ3FR")}/>*/}
        </DGListView>


        {/* 网站底部 */}
        <DGFooterView/>
    </DGFadeView>);
}
export default DGSecurityIndex;